package com.csnf.servlet;

import com.csnf.entity.Course;
import com.csnf.service.CourseService;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class CourseServlet {
    @WebServlet("/courses")
    public class CourseController extends HttpServlet {
        private final CourseService courseService = new CourseService();

        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            List<Course> courses = courseService.getAllCourses();
            request.setAttribute("courses", courses);
            RequestDispatcher dispatcher = request.getRequestDispatcher("course-list.jsp");
            dispatcher.forward(request, response);
        }
    }

}
